package cn.gcjxsc.controller.api;

import cn.gcjxsc.controller.merchant.MerchantBaseController;
import cn.gcjxsc.data.query.salesman.IntegralRecordQuery;
import cn.gcjxsc.data.vo.salesman.statics.IntegralRecordVo;
import cn.gcjxsc.entity.salesman.IntegralRecord;
import cn.gcjxsc.service.integral.IntegralRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author pumbaa
 * @since 1.0
 */
@RestController("apiStaticsController")
@RequestMapping("/statics")
public class StaticsController extends MerchantBaseController {
    @Autowired
    private IntegralRecordService integralRecordService;


    /**
     * 查询业务流水记录
     *
     * @return
     */
    @RequestMapping("/salesman/integralRecord/list")
    public Map<String, Object> findSalesmanIntegralRecordList(IntegralRecordQuery filter,
                                                              @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                                                              @RequestParam(value = "pageSize", defaultValue = "30", required = false) int pageSize) {
        filter.format();
        Page<IntegralRecord> pageList = integralRecordService.findList(filter, page, pageSize);
        List<IntegralRecordVo> voList = new ArrayList<>();
        if (pageList.getContent().size() > 0) {
            voList = integralRecordService.convertList(pageList.getContent());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("list", voList);
        map.put("total", pageList.getTotalElements());
        return map;
    }
}


